<?php
namespace app\patrol\logic;

class DayPatolLogic extends PatrolLogic {

    /**
     * 更新日常巡店楼层
     * @param $openid
     * @param $cp_type
     * @param $crm_detail
     * @return mixed
     */
    public function save_dp_floor($openid,$cp_type,$crm_detail){
        $cf_data = [];
        $cf_data['end_time'] = date('Y-m-d H:i:s');
        $cf_data['status'] = 1;

        $maps = [];
        $maps[] = ['id','=',$crm_detail['cp_floorid']];
        $r = model('cp_floor')->force()->save($cf_data,$maps);
        if($r !== false){
            $maps = [];
            $maps[] = ['cp_type','=',$cp_type];
            $maps[] = ['cp_floorid','=',$crm_detail['cp_floorid']];
            $crmids = model('cp_region_modular')->get_column($maps,'id');

            $m = new \app\common\controller\Matter();
            $c = new \app\common\controller\Copy();
            foreach($crmids as $k => $v){
                //生成事项（打开）
                $r = $m->save_matter_open($openid,$v,1);
                //生成抄送（已抄送）
                $r = $c->save_copy_open($openid,$v,1);
            }

            //更新日常巡店积分
            $si = new \app\common\controller\SaveIntegral();
            $r = $si->save_dp_integral($crm_detail['cp_floorid']);
            return $this->get_response(1,'OK');
        }
        return $this->get_response(0,'更新日常巡店楼层失败');
    }
}